package org.gap.wizards.items;

import org.gap.wizards.utils.Persistence;
import org.gap.wizards.views.ViewPlatform;
import org.gap.wizards.views.ViewPlatform.Color;

public class Description {

	private final String name;
	private final char symbol;
	private final Color symbolColor;
	private final boolean canBeEquiped;

	public Description(String name, char symbol, Color symbolColor) {
		this(name, symbol, symbolColor, false);
	}
	
	public Description(String name, char symbol, Color symbolColor, boolean canBeEquiped) {
		this.name = name;
		this.symbol = symbol;
		this.symbolColor = symbolColor;
		this.canBeEquiped = canBeEquiped;
	}

	public String name() {
		return name;
	}

	public boolean canBeEquiped() {
		return canBeEquiped;
	}

	public void print(ViewPlatform console, int x, int y) {
		console.print(x, y, symbolColor, symbol);
	}

	public void persist(Persistence persist) {
		persist.set("name", name);
		persist.set("symbol", symbol);
		persist.set("symbol.color", symbolColor.name());
	}
	
	public static Description load(Persistence data) {
		String name = data.getString("name");
		char symbol = (char)data.getInt("symbol");
		String color = data.getString("symbol.color");
		return new Description(name, symbol, Color.valueOf(color));
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (!obj.getClass().equals(Description.class)) {
			return false;
		}
		Description other = (Description)obj;
		return name.equals(other.name) && symbol == other.symbol && symbolColor == other.symbolColor;
	}
}
